//
// Created by Semir on 2020/5/25.
//

#include <iostream>
#include <vector>

using namespace std;

int FindGreatestSumOfSubArray(vector<int> array) {
    int sum = 0;
    int maxVal = -99999999;
    for (int i : array) {
        sum = max(sum + i, i);
        if (sum > maxVal) {
            maxVal = sum;
        }
    }
    return maxVal;
}

int main() {
    vector<int> array = {-2, 6, -3, -2, 7, -15, 1, 2, 2};
    int res = FindGreatestSumOfSubArray(array);
    cout << res << endl;
    return 0;
}